export default function defaultToVfrom(content) {
  const controls =  (content instanceof Array)?content:  JSON.parse(content || "") || [];

  let widgetList = [];

  for (let i = 0; i < controls.length; i++) {
    let control = controls[i];
    let widget = null;
    switch (control.type) {
      case "string":
        widget = {
          type: "input",
          icon: "text-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            type: "text",
            defaultValue: control.default,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            clearable: true,
            showPassword: false,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: [],
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            minLength: null,
            maxLength: null,
            showWordLimit: false,
            prefixIcon: "",
            suffixIcon: "",
            appendButton: false,
            appendButtonDisabled: false,
            buttonIcon: "el-icon-search",
            onCreated: "",
            onMounted: "",
            onInput: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
            onAppendButtonClick: "",
          },
          id: control.field,
        };

        break;
      case "textarea":
        widget = {
          type: "textarea",
          icon: "textarea-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            rows: 3,
            defaultValue: control.default,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            minLength: null,
            maxLength: null,
            showWordLimit: false,
            onCreated: "",
            onMounted: "",
            onInput: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;
      case "number":
        widget = {
          type: "input",
          icon: "text-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            type: "text",
            defaultValue: control.default,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            clearable: true,
            showPassword: false,
            required: false,
            requiredHint: "",
            validation: "number",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            minLength: null,
            maxLength: null,
            showWordLimit: false,
            prefixIcon: "",
            suffixIcon: "",
            appendButton: false,
            appendButtonDisabled: false,
            buttonIcon: "el-icon-search",
            onCreated: "",
            onMounted: "",
            onInput: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
            onAppendButtonClick: "",
          },
          id: control.field,
        };
        break;
      case "radio":
        widget = {
          type: "radio",
          icon: "radio-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            defaultValue: control.default,
            columnWidth: "200px",
            size: "",
            displayStyle: "inline",
            buttonStyle: false,
            border: false,
            labelWidth: null,
            labelHidden: false,
            disabled: false,
            hidden: false,
            optionItems: control.options,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onChange: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;
      case "checkbox":
        widget = {
          type: "checkbox",
          icon: "checkbox-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            defaultValue: control.default || [],
            columnWidth: "200px",
            size: "",
            displayStyle: "inline",
            buttonStyle: false,
            border: false,
            labelWidth: null,
            labelHidden: false,
            disabled: false,
            hidden: false,
            optionItems: control.options,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onChange: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;
      case "select":
        widget = {
          type: "select",
          icon: "select-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            defaultValue: control.default || [],
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            disabled: false,
            hidden: false,
            clearable: true,
            filterable: false,
            allowCreate: false,
            remote: false,
            automaticDropdown: false,
            multiple: false,
            multipleLimit: 0,
            optionItems: control.options,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onRemoteQuery: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };

        break;
      case "multipleselect":
        widget = {
          type: "select",
          icon: "select-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            defaultValue: control.default || [],
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            disabled: false,
            hidden: false,
            clearable: true,
            filterable: false,
            allowCreate: false,
            remote: false,
            automaticDropdown: false,
            multiple: true,
            multipleLimit: 0,
            optionItems: control.options,
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onRemoteQuery: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;
      case "date":
        widget = {
          type: "date",
          icon: "date-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            type: "date",
            defaultValue: control.default,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            clearable: true,
            editable: false,
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;
      case "time":
        widget = {
          type: "time",
          icon: "time-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            defaultValue: control.default,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            clearable: true,
            editable: false,
            format: "HH:mm:ss",
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: "",
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;

      case "datetime":
        widget = {
          type: "date",
          icon: "date-field",
          formItemFlag: true,
          options: {
            name: control.field,
            label: control.label,
            labelAlign: "",
            type: "datetime",
            defaultValue: null,
            placeholder: "",
            columnWidth: "200px",
            size: "",
            labelWidth: null,
            labelHidden: false,
            readonly: false,
            disabled: false,
            hidden: false,
            clearable: true,
            editable: false,
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            required: false,
            requiredHint: "",
            validation: "",
            validationHint: "",
            customClass: [],
            labelIconClass: null,
            labelIconPosition: "rear",
            labelTooltip: null,
            onCreated: "",
            onMounted: "",
            onChange: "",
            onFocus: "",
            onBlur: "",
            onValidate: "",
          },
          id: control.field,
        };
        break;

      case "table":
        widget = {
          type: "sub-form",
          category: "container",
          icon: "sub-form",
          widgetList: defaultToVfrom(control.options||[]),
          options: {
            name: control.field,
            showBlankRow: true,
            showRowNumber: true,
            labelAlign: "label-center-align",
            hidden: false,
            customClass: "",
            onSubFormRowAdd: "",
            onSubFormRowInsert: "",
            onSubFormRowDelete: "",
            onSubFormRowChange: "",
          },
        };
        break;

      default:
    }

    if (widget) {
      widgetList.push(widget);
    }
  }
  return {
    widgetList,
    formConfig: {
      modelName: "formData",
      refName: "vForm",
      rulesName: "rules",
      labelWidth: 80,
      labelPosition: "left",
      size: "",
      labelAlign: "label-left-align",
      cssCode: "",
      customClass: "",
      functions: "",
      layoutType: "PC",
      onFormCreated: "",
      onFormMounted: "",
      onFormDataChange: "",
      onFormValidate: "",
    },
  };
}
